package edu.pku.sei.gefcommon.descriptor.descriptors;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

public class SizePropertyDescriptor extends TextPropertyDescriptor {
	public SizePropertyDescriptor(Object id, String name,String catalog) {
		super(id, name);
		this.setCategory(catalog);
		this.setValidator(GeometryValidator.sizeValidator);
	}
	static public String fromModel(Dimension value){
		if(value==null) return "0,0";
		return value.width+","+value.height;
	}
	static public Dimension toModel(String value){
		String[] dt = value.split(",");
		Dimension d = new Dimension();
		d.width = Integer.parseInt(dt[0]);
		d.height = Integer.parseInt(dt[1]);
		return d;
	}
}
